import java.net.*; 
import java.io.*; 

public class Server_Thread extends Thread
{ 
 protected Socket clientSocket;

 public Server_Thread (Socket clientSoc)
   {
    clientSocket = clientSoc;
   }

 public void run()
   {
    System.out.println ("Iniciando hilo......");

    try { 
         PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), 
                                      true); 
         BufferedReader in = new BufferedReader( 
                 new InputStreamReader( clientSocket.getInputStream())); 

         String inputLine; 

         while ((inputLine = in.readLine()) != null) 
             { 
              System.out.println ("Server: " + inputLine); 
              //para hacer ECHO, le envio lo que he recibido
              out.println("ECHO:"+inputLine); 

              if (inputLine.equals("Bye.")) 
                  break; 
             } 

         out.close(); 
         in.close(); 
         clientSocket.close(); 
         
        } 
    catch (IOException e) 
        { 
         System.err.println("Problem with Communication Server");
         System.exit(1); 
        } 
    }
}